
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class RainbowProgressIndicator extends StatefulWidget {
  const RainbowProgressIndicator({super.key});

  @override
  _RainbowProgressIndicatorState createState() => _RainbowProgressIndicatorState();
}

class _RainbowProgressIndicatorState extends State<RainbowProgressIndicator> with SingleTickerProviderStateMixin {
  late AnimationController controller;
  late Animation colorAnimation;

  @override
  void initState()
  {
    controller = AnimationController(duration: const Duration(seconds: 2), vsync: this,)..repeat(reverse: true);
    colorAnimation = TweenSequence<Color?>(
      [
        TweenSequenceItem(
          tween: ColorTween(begin: Colors.orange, end: Colors.red),
          weight: 1.w,
        ),
        TweenSequenceItem(
          tween: ColorTween(begin: Colors.red, end: Colors.green),
          weight: 1.w,
        ),
        TweenSequenceItem(
          tween: ColorTween(begin: Colors.green, end: Colors.blue),
          weight: 1.w,
        ),
      ],
    ).animate(controller);

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: controller,
      builder: (context,child){
        return CircularProgressIndicator(
          value: 1,
          strokeWidth: 3.w,
          color: colorAnimation.value, // 使用彩虹色动画
        );
      },
    );
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }
}
